# -*- coding:utf-8 -*-
#! /bin/python

def letter_n_gram(letter, n):
    if n > len(letter) or n < 1:
        return [letter]
    ret = []
    for i in range(len(letter)):
        if i + n -1 >= len(letter):
            break
        ret.append(letter[i:i+n])
    return ret


def letter_all_gram(letter,_min=3):
    l = len(letter)
    if _min > l:
        return [letter]
    ret = []
    for i in range(_min,l+1,1):
        ret.extend(letter_n_gram(letter,i))
    return ret

def list_n_gram(l,n):
    ret = []
    lg = letter_n_gram(l,n)
    for i in lg:
        g = "".join(i)
        ret.append(g)
    return ret


if __name__ == '__main__':
    print(letter_n_gram("ab", 3))
    print(letter_n_gram("abcdef",2))
    print(letter_n_gram(["abcdef","123456","@@@@"], 2))

    print(letter_all_gram("abcd"))
    print(letter_all_gram("abcd",5))
    print(letter_n_gram('\xe7\x9b\xb4\xe8\x86\x9d\xe7\xa1\xac\xe4\xb8\xbe',4))

    print(list_n_gram(["abcdef","123456","@@@@"], 2))

    """
    ['ab']
    ['ab', 'bc', 'cd', 'de', 'ef']
    [['abcdef', '123456'], ['123456', '@@@@']]
    ['abc', 'bcd', 'abcd']
    ['abcd']
    ['\xe7\x9b\xb4\xe8', '\x9b\xb4\xe8\x86', '\xb4\xe8\x86\x9d', '\xe8\x86\x9d\xe7', '\x86\x9d\xe7\xa1', '\x9d\xe7\xa1\xac', '\xe7\xa1\xac\xe4', '\xa1\xac\xe4\xb8', '\xac\xe4\xb8\xbe']
    """
    pass